package com.duing.dao;

import com.duing.bean.Guest;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class GuestDao {
    static List<Guest> guestList=new ArrayList<>();
    static {
        guestList.add(new Guest("小明","店长"));
        guestList.add(new Guest("小红","助理"));
        guestList.add(new Guest("小黑","服务员"));
        guestList.add(new Guest("小狗","厨师"));
        guestList.add(new Guest("小白","CEO"));
        guestList.add(new Guest("小许","世界总统"));
    }

    public  List<Guest> getGuestList() {
        return guestList;
    }
    public void add(Guest guest){
        guestList.add(guest);
    }
    public void update(Guest newguest){
        Guest oldguest=get(newguest.getName());
        oldguest.setRole(newguest.getRole());

    }
    public void delete(String name){
        Guest guest=get(name);
        guestList.remove(guest);
    }



    public Guest get(String name){
        for(Guest guest:guestList){
            if(guest.getName().equals(name)){//名字一样找到了
                return guest;
            }
        }
        return new Guest("","");
    }
}
